package edu.njpi.vueajax.controller;



import com.google.gson.Gson;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

import static org.apache.logging.log4j.message.MapMessage.MapFormat.JSON;

@Controller
public class RequestController {
    @CrossOrigin
    @GetMapping(value = "/get")
    @ResponseBody
    public String login(@RequestParam String name, @RequestParam String password){
        Map<String,String> mp=new HashMap<>();
        Gson gson=new Gson();
        if(name.equals("zhangsan") && password.equals("123456")){
            mp.put("result","ok");
            mp.put("msg","用户名密码正确");
        }else{
            mp.put("result","error");
            mp.put("msg","用户名密码错误！");
        }
        return  gson.toJson(mp);

    }
    @GetMapping(value = "/test")
    @ResponseBody
    public String login2(){
        
        return  "{\"name\":\"helle word!\"}";

    }
    @CrossOrigin
    @PostMapping(value = "/post")
    @ResponseBody
    public String  post(@RequestParam String name, @RequestParam String password){
        Map<String,String> mp=new HashMap<>();
        Gson gson=new Gson();
        if(name.equals("zhangsan") && password.equals("123456")){
            mp.put("result","ok");
            mp.put("msg","用户名密码正确");
        }else{
            mp.put("result","error");
            mp.put("msg","用户名密码错误！");
        }
        return  gson.toJson(mp);

    }
}
